package test_junit_shop;

import org.omg.PortableServer.THREAD_POLICY_ID;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.Select;
import util.BaseDriver;

/**
 * Created by CYH on 2018/2/08.
 * 门店
 * 调拨：
 1、A门店：跨店调拨入库 - 申请调拨
 2、B门店：跨店调拨出库 - 先配货再填写物流信息
 3、A门店：调拨单入库核对
 4、A门店：调拨单结算
 */

public class ShopAllocationStorage extends BaseDriver{

    private ShopAllocationStorage(){}
    private static ShopAllocationStorage instance=new ShopAllocationStorage();
    public static ShopAllocationStorage getInstance(){
        return instance;
    }


    public void sendAllocation() throws InterruptedException {

        driver.switchTo().frame(2);
        driver.findElement(By.cssSelector("button.btn.btn-sm.btn-outline.btn-primary")).click();
        Thread.sleep(2000);
        driver.switchTo().frame(0);
        driver.findElement(By.id("add_btn")).click();
        Thread.sleep(2000);
        driver.switchTo().parentFrame();
        driver.switchTo().frame(1);
        driver.switchTo().frame(0);
        Thread.sleep(1000);
        driver.findElement(By.id("44172_anchor")).click();
        driver.switchTo().parentFrame();
        driver.switchTo().frame(1);
        Thread.sleep(2000);
        driver.findElement(By.xpath("(//input[@name='btSelectItem'])[2]")).click();
        driver.switchTo().parentFrame();
        driver.switchTo().parentFrame();
        driver.findElement(By.cssSelector("#layui-layer2 > div.layui-layer-btn > a.layui-layer-btn0")).click();

        Thread.sleep(2000);
        driver.switchTo().frame(0);
        driver.findElement(By.name("productNum")).click();
        driver.findElement(By.name("productNum")).clear();
        driver.findElement(By.name("productNum")).sendKeys("10");
        driver.findElement(By.cssSelector("span.type")).click();
        driver.findElement(By.cssSelector("li > i")).click();
        driver.findElement(By.name("storehouse")).click();
        new Select(driver.findElement(By.name("storehouse"))).selectByVisibleText("门店创建仓库");
        driver.findElement(By.cssSelector("option[value=\"36\"]")).click();

        driver.switchTo().parentFrame();
        driver.findElement(By.linkText("确定")).click();
    }

    public void outAllocation() throws InterruptedException {
        Thread.sleep(2000);
        driver.switchTo().parentFrame();
        driver.findElement(By.cssSelector("img[alt=\"image\"]")).click();
        driver.findElement(By.xpath("//ul[@id='change-auth']/li[9]/a/span/b")).click();
        driver.findElement(By.cssSelector("button.closebtn")).click();
        driver.findElement(By.xpath("//ul[@id='side-menu']/li[3]/a/span")).click();
        Thread.sleep(2000);
        driver.findElement(By.linkText("出库管理")).click();
        driver.findElement(By.linkText("跨店调拨出库")).click();
        Thread.sleep(2000);
        driver.switchTo().frame(2);
        driver.findElement(By.name("btSelectItem")).click();
        driver.findElement(By.cssSelector("button.btn.btn-sm.btn-outline.btn-primary")).click();
        Thread.sleep(1000);
        driver.switchTo().frame(1);
        driver.findElement(By.cssSelector("select")).click();
        new Select(driver.findElement(By.cssSelector("select"))).selectByVisibleText("555");
        driver.findElement(By.cssSelector("option[value=\"56\"]")).click();
        driver.findElement(By.cssSelector("input.price_3")).click();
        driver.findElement(By.cssSelector("input.price_3")).clear();
        driver.findElement(By.cssSelector("input.price_3")).sendKeys("10");
        driver.findElement(By.id("paymentSelect")).click();
        new Select(driver.findElement(By.id("paymentSelect"))).selectByVisibleText("现金");
        driver.findElement(By.cssSelector("option[value=\"7007\"]")).click();
        driver.switchTo().parentFrame();
        driver.findElement(By.linkText("确定")).click();
        Thread.sleep(3000);
        driver.findElement(By.name("btSelectItem")).click();
        driver.findElement(By.cssSelector("button.btn.btn-sm.btn-outline.btn-info")).click();
        Thread.sleep(2000);
        driver.switchTo().frame(1);
        driver.findElement(By.name("logisticsNo")).click();
        driver.findElement(By.name("logisticsNo")).clear();
        driver.findElement(By.name("logisticsNo")).sendKeys("5555");
        driver.findElement(By.name("logisticsFee")).click();
        driver.findElement(By.name("logisticsFee")).clear();
        driver.findElement(By.name("logisticsFee")).sendKeys("5");
        Thread.sleep(1000);
        driver.switchTo().parentFrame();
        driver.findElement(By.linkText("确定")).click();
    }

    public void checkAllocation() throws InterruptedException {
        Thread.sleep(1000);
        driver.switchTo().parentFrame();
        driver.findElement(By.cssSelector("img[alt=\"image\"]")).click();
        driver.findElement(By.xpath("//ul[@id='change-auth']/li[5]/a/span/b")).click();
        driver.findElement(By.cssSelector("button.closebtn")).click();
        driver.findElement(By.xpath("//ul[@id='side-menu']/li[3]/a/span")).click();
        Thread.sleep(2000);
        driver.findElement(By.linkText("入库管理")).click();
        driver.findElement(By.linkText("调拨单入库核对")).click();
        Thread.sleep(2000);
        driver.switchTo().frame(2);
        driver.findElement(By.name("btSelectItem")).click();
        driver.findElement(By.xpath("//button[@type='button']")).click();
        Thread.sleep(2000);
        driver.switchTo().frame(0);
        driver.findElement(By.cssSelector("input.price_3")).click();
        driver.findElement(By.cssSelector("input.price_3")).clear();
        driver.findElement(By.cssSelector("input.price_3")).sendKeys("10");
        driver.switchTo().parentFrame();
        driver.findElement(By.linkText("确定")).click();
    }

    public void payAllocation() throws InterruptedException {
        Thread.sleep(3000);
        driver.switchTo().parentFrame();
        driver.findElement(By.xpath("//ul[@id='side-menu']/li[4]/a/span")).click();
        Thread.sleep(1000);
        driver.findElement(By.linkText("调拨单结算")).click();
        Thread.sleep(2000);
        driver.switchTo().frame(3);
        driver.findElement(By.name("btSelectItem")).click();
        driver.findElement(By.xpath("//button[@type='button']")).click();
        Thread.sleep(1000);
        driver.findElement(By.linkText("确定支付")).click();
    }









}
